Socket
Socket
Sign inDemoInstall

duplexify

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

duplexify

Turn a writable and readable stream into a streams2 duplex stream with support for async initialization and streams1/streams2 input


Version published
Weekly downloads
14M
decreased by-21.81%
Maintainers
1
Weekly downloads
 
Created

What is duplexify?

The duplexify npm package allows you to turn a writable and readable stream into a single duplex stream. This can be useful when you need to present a single stream interface while having separate underlying sources for the readable and writable sides.

What are duplexify's main functionalities?

Creating a duplex stream from separate readable and writable streams

This feature allows you to combine a readable stream and a writable stream into a duplex stream, which can be both read from and written to.

const duplexify = require('duplexify');
const fs = require('fs');

const readable = fs.createReadStream('source.txt');
const writable = fs.createWriteStream('destination.txt');
const duplexStream = duplexify(writable, readable);

// Now you can read from and write to duplexStream as if it were a single stream.

Dynamically setting the readable or writable part of the duplex stream

This feature allows you to dynamically set or swap out the readable and writable components of the duplex stream after it has been created.

const duplexify = require('duplexify');
const duplexStream = duplexify();

duplexStream.setReadable(readableStream);
duplexStream.setWritable(writableStream);

Handling errors and closing the stream properly

This feature demonstrates how to handle errors and the closing of the duplex stream, ensuring that resources are cleaned up properly.

const duplexify = require('duplexify');
const duplexStream = duplexify(writable, readable);

duplexStream.on('error', (err) => {
  console.error('Stream error:', err);
});

duplexStream.on('finish', () => {
  console.log('Writable stream finished writing.');
});

duplexStream.on('end', () => {
  console.log('Readable stream finished reading.');
});

Other packages similar to duplexify

Keywords

FAQs

Package last updated on 04 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc